//引入第三方包 express
var express = require('express');
//引入第三方包 express-jwt
var { expressjwt } = require('express-jwt')
//实例化express
var app = express()
//设置静态资源托管文件夹
app.use(express.static('static'));
//在所有接口前设置 处理post请求参数的中间件
app.use(express.json());
app.use(express.urlencoded({ extended: false }))

app.use(expressjwt({
    secret: '1234',
    algorithms: ['HS256'],
}).unless({ path: ['/user/login', '/user/register', '/user/add'] }))
//导入拆分出去的子路由
var userRouter = require('./router/userRouter')
app.use('/user', userRouter)
//设置监听
app.listen(8080, () => {
    console.log('服务端运行在: http://localhost:8080');
})